package controller

import (
	"github.com/gin-gonic/gin"
	"log"
	"ms_sg_game/constant"
	"ms_sg_game/server/common"
	"ms_sg_game/server/web/logic"
	"ms_sg_game/server/web/model"
	"net/http"
)

var DefaultAccountController = &AccountController{}

type AccountController struct {
}

func (a *AccountController) Register(ctx *gin.Context) {
	//1 获取参数
	req := &model.RegisterReq{}
	err := ctx.ShouldBind(req) //这里是GET请求
	if err != nil {
		ctx.JSON(http.StatusOK, common.Error(constant.InvalidParam, "参数不合法"))
		return
	}
	//2 判断当前用户是否注册
	err = logic.DefaultAccountLogin.Register(req)
	//3 返回结果
	if err != nil {
		log.Println("注册业务失败:", err)
		ctx.JSON(http.StatusOK, common.Error(err.(*common.MyError).Code(), err.Error()))
		return
	}
	ctx.JSON(http.StatusOK, common.Success(constant.OK, nil))
}
